<?php 
class MD_Product
{
	public static function getProductById($id)
	{
		$product = TN_Db::getInstance()->fetchAll("SELECT * FROM product where id = '$id' ");
    	return $product[0];
	} 
	
	public static function getHightProducts($limit = '')
	{
		$sql = "select * from product where hightlight = 1 $limit";
		return TN_Db::getInstance()->fetchAll($sql);
	}
	
	public static function getProductsByCategory($c)
	{
		return TN_Db::getInstance()->fetchAll("SELECT * FROM product  where id_category = '$c' ORDER BY id");
	}
	
	public static function setImage($id, $img)
	{
		TN_Db::getInstance()->update('product', array('image' => $img), "id = '$id' ");
	}
	
	public static function add( $title, $content, $enabled, $price , $image , $category , $highlight)
	{
		TN_Db::getInstance()->insert('product', array('title'=> $title, 'description' => $content,'enabled' => $enabled , 'price' => $price, 'image' => $image ,'id_category' => $category, 'hightlight' => $highlight));
	}
 	public static function lastId()
    {
    	return TN_Db::getInstance()->lastInsertId('product');
    }
	public static function update( $id , $title, $content, $enabled, $price, $image , $category, $hightlight )
	{
		TN_Db::getInstance()->update('product', array('title'=> $title, 'description' => $content,'enabled' => $enabled, 'price' => $price, 'image' => $image,'id_category' => $category, 'hightlight' => $hightlight), "id = '$id' ");
	}
	
	public static function delete ($id )
	{
		TN_Db::getInstance()->delete('product', "id = '$id' ");
	}
}
?>